import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:scan/scan.dart';
import 'package:openim_common/openim_common.dart';

class ScanPage extends StatefulWidget {
  const ScanPage({Key? key}) : super(key: key);

  @override
  State<ScanPage> createState() => _ScanPageState();
}

class _ScanPageState extends State<ScanPage> {
  ScanController controller = ScanController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(StrRes.scan),
        backgroundColor: Colors.black,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back, color: Colors.white),
          onPressed: () => Get.back(),
        ),
        actions: [
          IconButton(
            icon: const Icon(Icons.flash_on, color: Colors.white),
            onPressed: () {
              controller.toggleTorchMode();
            },
          ),
        ],
      ),
      body: ScanView(
        controller: controller,
        scanAreaScale: 0.7,
        scanLineColor: Colors.green,
        onCapture: (data) {
          // 扫描成功，返回结果
          Get.back(result: data);
        },
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}